﻿using System;
using System.Data;
using DMS.Business.Modules.Statistics;
using System.Text;
using InfoSoftGlobal;

namespace DMS.Web.Modules.Statistics
{
    public partial class StatByInsuranceControl : System.Web.UI.UserControl
    {
        private int _chartWidth=400;
        public int ChartWidth
        {
            get
            {
                return _chartWidth;
            }
            set
            {
                _chartWidth = value;
            }
        }

        private int _chartHeigth = 400;
        public int ChartHeight
        {
            get
            {
                return _chartHeigth;
            }
            set
            {
                _chartHeigth = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Stat();
            }
        }

        private void Stat()
        {
            string condition = "";//string.Format(" and InitialTime >= '{0}'", new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1));

            DataSet ds = new StatService().StatByInsurance(condition);

            DrawChart(ds);
        }

        /// <summary>
        ///  画图
        /// </summary>
        private void DrawChart(DataSet ds)
        {
            StringBuilder xmlData = new StringBuilder();
            //xmlData.Append("<chart caption='参保类型统计'  baseFontSize='15' showAboutMenuItem='0' xAxisName='统计单位'  showValues='1' formatNumberScale='0' showBorder='0'>");
            xmlData.Append(
                string.Format(
                    "<chart caption='参保类型统计'  baseFontSize='15' showAboutMenuItem='0' decimals='2' enableSmartLabels='1' enableRotation='0' bgAngle='360' showBorder='0' startingAngle='70' bgColor=''>"));
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                xmlData.Append(string.Format("<set label='{0}' value='{1}' />","养老",row["Yanglao"]));
                xmlData.Append(string.Format("<set label='{0}' value='{1}' />","工伤",row["Gongshang"]));
                xmlData.Append(string.Format("<set label='{0}' value='{1}' />","失业",row["Shiye"]));
                xmlData.Append(string.Format("<set label='{0}' value='{1}' />","医疗",row["Yiliao"]));
                xmlData.Append(string.Format("<set label='{0}' value='{1}' />","生育",row["Shengyu"]));
            }
            xmlData.Append("</chart>");
            litChart1.Text = FusionCharts.RenderChart("../../FusionCharts/Pie2D.swf", "", xmlData.ToString(), "myChart2",  "100%",ChartHeight.ToString(), false, true); 
        }
    }
}